//
//  AddTipTextViewController.m
//  TipsProject
//
//  Created by Suny on 15/5/22.
//  Copyright (c) 2015年 Suny. All rights reserved.
//

#import "AddTipTextViewController.h"
#import "UIBarButtonItem+BaseFramework.h"
@implementation AddTipTextViewController


- (UITextView *)textView
{
	if (!_textView)
	{
		_textView = [[UITextView alloc] init];
		_textView.layer.borderWidth = 1;
		_textView.layer.borderColor = [UIColor colorWithHexString:@"E6E6E6"].CGColor;
		_textView.layer.borderWidth = 4;
	}
	return _textView;
}

- (id)init
{
	self = [super init];
	if (self)
	{
		self.hasNavigationBar = YES;
		[self setNavigationTitle: @"添加文本"];
	}
	return self;
}

- (void)viewDidLoad
{
	[super viewDidLoad];
	self.navigationItem.leftBarButtonItem = [UIBarButtonItem leftBarButtonItemWithImageName:@"navigationbar_back_icon"
																				  target:self
																				selector:@selector(back)];
	
	self.navigationItem.rightBarButtonItem = [UIBarButtonItem leftBarButtonItemWithTitle:@"完成"
																				  target:self
																				selector:@selector(handleFinishText)];
	[self.view addSubview:self.textView];
	
	self.textView.frame = CGRectMake(10, 
									 self.navigationBarHeight + 10, 
									 self.view.width - 20,
									 (self.view.height - self.navigationBarHeight - 10)/2);
	
	

}

- (void)handleFinishText
{
	if (self.finishBlock(self.textView.text))
	{
		[self dismissViewControllerAnimated:YES completion:nil];
	}
}

- (void)back
{
	[self dismissViewControllerAnimated:YES completion:nil];

}


- (void)viewDidAppear:(BOOL)animated
{
	[super viewDidAppear:animated];
	
	[self.textView becomeFirstResponder];
}
@end
